package com.ukayunnuo.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;
import javax.sql.DataSource;


/**
 * tdengine 数据源配置
 */
@Slf4j
@Configuration
public class DataSourceConfig {

    @Resource
    private TdengineProperties tdengineProperties;

    @Bean(name = "tdengineDataSource")
    public DataSource tdengineDataSource() {
        DataSource dataSource = DataSourceBuilder.create()
                .driverClassName(tdengineProperties.getDriverClassName())
                .url(tdengineProperties.getUrl())
                .username(tdengineProperties.getUsername())
                .password(tdengineProperties.getPassword())
                .build();
        log.info("init tdengineDataSource properties:{}", tdengineProperties);
        return dataSource;
    }
}